﻿#region Vương văn hùng
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

using DataAccess;
using Entities;
using Common;

namespace BusinessLogic
{
    public static  class HienThiHangHoaListview
    {
        public static Entities.HienThiHangHoaListview[] SelectChiTietHangHoaCacBang(Entities.HienThiHangHoaListview hoadon)
        {
            Entities.HienThiHangHoaListview[] list = null;
            try
            {
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand("exec sp_Select_ChiTietHangHoaCacBang @HanhDong,@MaKho,@MaNhaCungCap,@MaHoaDon", cn);
                cmd.Parameters.Add("HanhDong", SqlDbType.NVarChar).Value = hoadon.HanhDong;
                cmd.Parameters.Add("MaKho", SqlDbType.VarChar).Value = hoadon.MaKho;
                cmd.Parameters.Add("MaNhaCungCap", SqlDbType.VarChar).Value = hoadon.MaNhaCungCap;
                cmd.Parameters.Add("MaHoaDon", SqlDbType.VarChar).Value = hoadon.MaHoaDon;
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                ArrayList arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.HienThiHangHoaListview row = new Entities.HienThiHangHoaListview();
                    row.MaHangHoa = dr["MaHangHoa"].ToString();
                    row.TenHangHoa = dr["TenHangHoa"].ToString();
                    row.SoLuong = dr["SoLuong"].ToString();
                    row.MaDonViTinh = dr["MaDonViTinh"].ToString();
                    row.TenDonViTinh = dr["TenDonViTinh"].ToString();
                    row.HanSuDung = dr["HanSuDung"].ToString();
                    row.GiaNhap = dr["GiaNhap"].ToString();
                    row.GiaBanBuon = dr["GiaBanBuon"].ToString();
                    row.GiaBanLe = dr["GiaBanLe"].ToString();
                    row.ChietKhau = dr["ChietKhau"].ToString();
                    row.ChietKhauThuongMai = dr["ChietKhauThuongMai"].ToString();
                    row.Thue = dr["Thue"].ToString();
                    row.SoLuongConLai = dr["SoLuongConLai"].ToString();
                    row.TongDaChietKhau = dr["ThanhTien"].ToString();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0)
                {
                    list = null;
                }
                else
                {
                    list = new Entities.HienThiHangHoaListview[n];
                    for (int i = 0; i < n; i++)
                    {
                        list[i] = (Entities.HienThiHangHoaListview)arr[i];
                    }
                }
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
                list = null;
            }
            return list;
        }
    }
}
#endregion
